use DBI;

# db に接続
$data_source = 'DBI:Pg:dbname=MarketDatabase';
$user_name = 'jiro';
$db = DBI->connect( $data_source, $user_name ) || die $db->errstr;

$sql = "select code, name from country_master_table order by code;";
$st = $db->prepare( $sql ) or die $db->errstr;
$st->execute() or die $db->errstr;

while ( ( $code, $name ) = $st->fetchrow_array() ) {
#	print $code . " " . $name . "\n";
	@tokens = split /\s/, $name;
	$enum_name = "";
	for $token ( @tokens ) {
		$enum_name .= $token;
	}
	if ( $enum_name =~ /(\w*\d*)/ ) {
		$enum_name = $1;
	}
	$enum_name = $enum_name . " = " . $code . ",";
	print "$enum_name\n";
}

$st->finish();


open F, ">new_file";
print F "this is new file";
close F;